package mapper;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;
import pojo.Order;

import java.util.List;

@Repository
public interface OrderMapper {

    /**
     * 查询所有订单
     *
     * @return
     */
    @Select("select * from orderform")
    List<Order> selectAll();

    /**
     * 根据orderid删除订单
     *
     * @param orderId
     * @return int代表删除行数
     */
    @Delete("delete from orderform where orderid=#{orderId}")
    int deleteById(String orderId);

    /**
     * 条件查询
     *
     * @param order
     * @return
     */
    List<Order> selectByConditions(Order order);

    /**
     * 更新订单数据
     *
     * @param order
     * @return
     */
    @Update("update orderform set orderdate=#{orderdate},totalnum=#{totalnum}, totalamount=#{totalamount}, payment=#{payment}, deliver=#{deliver}, receiver=#{receiver}, address=#{address}, phone=#{phone},postcode=#{postcode},state=#{state} where orderid=#{orderid}")
    int update(Order order);

    /**
     * 插入订单数据
     *
     * @param order
     * @return
     */
    @Insert("insert into orderform values(#{orderid},#{orderdate},#{userid},#{totalnum},#{totalamount},#{payment},#{deliver},#{receiver},#{address},#{phone},#{postcode},#{state})")
    int insert(Order order);

    /**
     * 根据订单删除数据
     *
     * @param userid
     * @return
     */
    @Select("select * from orderform where orderid=#{orderid}")
    Order selectById(String userid);

}
